package filehandler;

import entity.PoemInfo;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

/**
 * 
 * @author huwei
 *将初筛选后的信息对象存入本地文件中
 */
public class PushIntoFile {
	public static void push(List<PoemInfo> poemInfoList) {
		// 至此已获取HTML中的一行
		try {
			FileOutputStream file_fos = new FileOutputStream("data.txt",true);//设置为true, 追加模式
			OutputStreamWriter file_osw = new OutputStreamWriter(file_fos, "UTF-8");
			BufferedWriter file = new BufferedWriter(file_osw);

			for(PoemInfo p:poemInfoList){
				file.write(p.title); file.write("\t");
				file.write(p.author); file.write("\t");
				file.write(p.content); file.write("\t");
				file.write(p.tag); file.newLine();//回车换行
			}

			file.close();
			file_osw.close();
			file_fos.close();

		} catch (IOException e) {
			System.out.println("Error:" + e.getMessage());
		}

	}
}
